package com.huangyi;
public class Main {
    public static void main(String[] args) {
        //移动零
        class Solution {
            public void moveZeroes(int[] nums) {
                for(int cur = 0,dest = -1; cur<nums.length;cur++){
                    if(nums[cur] != 0){
                        int tmp = nums[cur];
                        dest++;
                        nums[cur] = nums[dest];
                        nums[dest] = tmp;
                    }
                }
            }
        }

        //复写零
        class Solution {
            public void duplicateZeros(int[] arr) {
                int cur = 0, dest = -1;
                while(cur<arr.length){
                    if(arr[cur] == 0){
                        dest += 2;
                    }else{
                        dest ++;
                    }
                    if(dest>=arr.length-1){
                        break;
                    }
                    cur++;
                }

                if(dest == arr.length){
                    arr[dest-1] = 0;
                    dest -= 2;
                    cur --;
                }

                while(cur>=0){
                    if(arr[cur] == 0){
                        arr[dest--] = 0;
                        arr[dest--] = 0;
                        cur--;
                    }else{
                        arr[dest--] = arr[cur--];
                    }
                }

            }
        }
    }

}